package com.example.sharding.demo.service;

import com.example.sharding.demo.config.ShardDataSourceProperties;
import com.example.sharding.demo.model.BaseEntity;
import com.example.sharding.demo.model.table.User;
import com.example.sharding.demo.utils.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
public class GlobalService {

    @Autowired
    private ShardDataSourceProperties properties;


    public void setQueryTimeRange(BaseEntity<User> record){
        if (record.getQueryStartTime() == null) {
            record.setQueryStartTime(DateUtil.str2Date(properties.getStartTime(),null));
        }
        if (record.getQueryEndTime() == null) {
            record.setQueryEndTime(new Date());
        }
    }

}
